package com.pureut.production.controller;

import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.production.domain.WasteTube;
import com.pureut.production.domain.dto.WasteTubeDto;
import com.pureut.production.domain.vo.WasteTubeVo;
import com.pureut.production.service.IWasteTubeService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description 废料管理
 * @Date 23-02-21
 * @Author hl
 **/
@RestController
@RequestMapping("/wasteTube")
public class WasteTubeController extends BaseController {

    @Resource
    private IWasteTubeService wasteTubeService;

    /**
     * 查询废料管理
     */
    @RequiresPermissions("productionTube:prostatistics:wastemanage:list")
    @GetMapping("/list")
    public TableDataInfo list(WasteTubeVo wasteTubeVo) {
        startPage();
        List<WasteTubeDto> list = wasteTubeService.selectWasteTubeList(wasteTubeVo);
        return getDataTable(list);
    }

    /**
     * 新增废料管理
     */
    @RequiresPermissions("production:wasteTube:list")
    @PostMapping
    public AjaxResult add(@Validated @RequestBody WasteTube wasteTube) {
        return toAjax(wasteTubeService.insertWasteTube(wasteTube));
    }

    /**
     * 根据编号获取详细信息
     */
    @RequiresPermissions("productionTube:prostatistics:wastemanage:codeAgain")
    @GetMapping(value = "/{wasteId}")
    public AjaxResult getInfo(@PathVariable long wasteId) {
        return AjaxResult.success(wasteTubeService.selectWasteTubeById(wasteId));
    }

    /**
     * 废料修正
     */
    @RequiresPermissions("productionTube:prostatistics:wastemanage:codeRepair")
    @Log(title = "废料管理", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody WasteTube WasteTube) {
        return toAjax(wasteTubeService.updateWasteTubeEdit(WasteTube));
    }

    /**
     * 根据物料号码获取肥料管理数据（fegin调用）
     */
    @GetMapping("/getWasteData")
    public AjaxResult getWasteData(String materialNumber) {
        return AjaxResult.success(wasteTubeService.getWasteData(materialNumber));
    }

    /**
     * 根据物料号码修改该物料入库时间（fegin调用）
     */
    @GetMapping("/upDateInTime")
    public void upDateInTime(String wasteScrapNumber) {
         wasteTubeService.upDateInTime(wasteScrapNumber);
    }

    /**
     * 根据物料号码修改该物料出库时间（fegin调用）
     */
    @GetMapping("/upDateOutTime")
    public void upDateOutTime(String wasteScrapNumber) {
        wasteTubeService.upDateOutTime(wasteScrapNumber);
    }

}
